package me.sealer.ssm.controller;

import lombok.extern.slf4j.Slf4j;
import me.sealer.ssm.constant.Dict;
import me.sealer.ssm.constant.RoleConstant;
import me.sealer.ssm.model.Role;
import me.sealer.ssm.service.RoleService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author sealer
 * @date 2016/09/27
 */
@Slf4j
@RequestMapping("/roleOperations")
@RequiresRoles(RoleConstant.ROLE_ADMIN)
@Controller
public class RoleController {
    private final RoleService roleService;

    public RoleController(RoleService roleService) {
        this.roleService = roleService;
    }

    @RequestMapping("/queryAllRoles")
    public ModelAndView queryAllRoles() {
        ModelAndView modelAndView = new ModelAndView();

        //调用service方法得到角色列表
        List<Role> roles = roleService.getRoles();
        //将得到的用户列表内容添加到ModelAndView中
        modelAndView.addObject(Dict.ROLES, roles);
        //设置响应的jsp视图
        modelAndView.setViewName("rolePermissionMgmt");

        return modelAndView;
    }
}
